package com.blockchain.front.servlets.financial;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.common.enums.GdState;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.exception.ParameterException;
import com.blockchain.front.service.common.entity.GdEntity;
import com.blockchain.front.service.financial.GdManage;
import com.blockchain.front.servlets.security.AbstractSceurityServlet;
import com.blockchain.util.parser.EnumParser;
import com.blockchain.util.parser.IntegerParser;

public class UpdatePdd extends AbstractSceurityServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		GdManage manage = serviceSession.getService(GdManage.class);
		GdEntity gdEntity = manage.getPd(id);
		if (id <= 0 || null == gdEntity ) {
			throw new ParameterException("该订单不存在");
		}
		request.setAttribute("gdEntity", gdEntity);
		request.setAttribute("type", request.getParameter("type"));
		forwardView(request, response,UpdatePdd.class);
	}
	
	@Override
	protected void processPost(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		GdState pdState = EnumParser.parse(GdState.class, request.getParameter("pdState"));
		GdManage manage = serviceSession.getService(GdManage.class);
		manage.updatePd(id,pdState);
		sendRedirect(request, response, getController().getURI(request, GdList.class));
	}

}